#pragma once

#include <arpa/inet.h>
#include <netinet/in.h>
#include <iostream>
#include <string>

#include "copyable.h"

// 封装地址类型
class InetAddress : public copyable
{
public:
    explicit InetAddress(uint16_t port = 0, std::string ip = "127.0.0.1");
    explicit InetAddress(const sockaddr_in &addr) : addr_(addr) {}

    std::string toIp() const;  // 获取Ip
    std::string toIpPort() const;  // 获取Ip端口号
    uint16_t toPort() const;  // 获取端口号

    const sockaddr_in* getSocAddr() const {return &addr_;}  // 不能通过返回的指针修改值
    void setSockAddr(const sockaddr_in& addr) {addr_ = addr; }
    
private:
    sockaddr_in addr_;
};